
import { requestClient } from '#/api/request';

// 查询人员返回值
interface ListOperateResult {
  rows: any[];
  total: number;
}

// 获取操作日志数据
export const listOperate = async (params: {
  pageNum: number;
  pageSize: number;
}) => {
  const response = await requestClient.get<ListOperateResult>('/manage/operate/list', { params });
  const data = response.rows; // 提取 rows 字段
  console.log("data:", data);

  const total = response.total;

  // 切片处理分页数据
  const result = data;

  // 使用对象映射简化业务类型转换逻辑
  const businessTypeMap: Record<number, string> = {
    0: '其他',
    1: '新增',
    2: '修改',
    3: '删除',
  };

  // 处理数据
  const mappedResult = result.map((row: any) => {
    return {
      ...row,
      statusFormatted: row.status === 0 ? '正常' : '异常',
      businessTypeFormatted: businessTypeMap[row.businessType] || '未知',
    };
  });

  console.log("mappedResult:", mappedResult);

  return {
    items: mappedResult,
    total: total,
  };
};

export const listOperateByEs = async (params: {
  pageNum: number;
  pageSize: number;
  search:string;
}) => {
  const response = await requestClient.get<ListOperateResult>('/monitor/operlog/es', { params });
  const data = response.rows; // 提取 rows 字段
  console.log("data:", data);

  const total = response.total;

  // 切片处理分页数据
  const result = data;

  // 使用对象映射简化业务类型转换逻辑
  // const businessTypeMap: Record<number, string> = {
  //   0: '其他',
  //   1: '新增',
  //   2: '修改',
  //   3: '删除',
  // };

  // 处理数据
  // const mappedResult = result.map((row: any) => {
  //   return {
  //     ...row,
  //     statusFormatted: row.status === 0 ? '正常' : '异常',
  //     businessTypeFormatted: businessTypeMap[row.businessType] || '未知',
  //   };
  // });

  //console.log("mappedResult:", mappedResult);

  return {
    items: result,
    total: total,
  };
};
